package com.sqfw.project.wpReport.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sqfw.framework.web.page.PageDomain;
import com.sqfw.framework.web.page.TableSupport;
import com.sqfw.project.wpReport.domain.SeatServiceReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.project.wpReport.domain.SeatWorkReport;
import com.sqfw.project.wpReport.service.ISeatWorkReportService;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.common.utils.poi.ExcelUtil;
import com.sqfw.framework.web.page.TableDataInfo;

/**
 * 坐席工作情况表Controller
 * 
 * @author lx
 * @date 2023-07-26
 */
@RestController
@RequestMapping("/wpReport/seatWorkReport")
public class SeatWorkReportController extends BaseController
{
    @Autowired
    private ISeatWorkReportService seatWorkReportService;

    /**
     * 查询坐席工作情况表列表
     */
    @PreAuthorize("@ss.hasPermi('getSeatWorkReportList')")
    @GetMapping("/getSeatWorkReportList")
    public TableDataInfo getSeatWorkReportList(SeatWorkReport seatWorkReport)
    {
        startPage();

        TableDataInfo tableDataInfo = seatWorkReportService.getSeatWorkReportList(seatWorkReport);

        List<SeatWorkReport> list = (List<SeatWorkReport>) tableDataInfo.getRows();
        if (list.size()>0){


            SeatWorkReport report = new SeatWorkReport();

            report.setCode("总计");
            //建单数量
//            int createWpCount = list.stream()
//                    .map(SeatWorkReport::getCreateWpCount)
//                    .reduce(Integer::sum)
//                    .orElse(0);
            int createWpCount = 10;
            report.setCreateWpCount(createWpCount);
            //归档数量
            int endCount = list.stream()
                    .map(SeatWorkReport::getEndCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setEndCount(endCount);
            //转督导
            int ddCount = list.stream()
                    .map(SeatWorkReport::getDdCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setDdCount(ddCount);
            //转质检
            int zjCount = list.stream()
                    .map(SeatWorkReport::getZjCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setZjCount(zjCount);

            //转培训助理
            int trainCount = list.stream()
                    .map(SeatWorkReport::getTrainCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setTrainCount(trainCount);

            //自办件
            int selfCount = list.stream()
                    .map(SeatWorkReport::getSelfCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSelfCount(selfCount);

            //流转件
            int moveCount = list.stream()
                    .map(SeatWorkReport::getMoveCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setMoveCount(moveCount);

            int visitSucessCount = list.stream()
                    .map(SeatWorkReport::getVisitSucessCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setVisitSucessCount(visitSucessCount);

            list.add(report);
        }


        return tableDataInfo;
    }

    /**
     * 导出坐席工作情况表列表
     */
    @Log(title = "坐席工作情况表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('getSeatWorkReportList:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SeatWorkReport seatWorkReport)
    {
        TableDataInfo tableDataInfo = seatWorkReportService.getSeatWorkReportList(seatWorkReport);
        List<SeatWorkReport> list = (List<SeatWorkReport>) tableDataInfo.getRows();
        if (list.size()>0){

            SeatWorkReport report = new SeatWorkReport();

            report.setCode("总计");
            //建单数量
            int createWpCount = list.stream()
                    .map(SeatWorkReport::getCreateWpCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setCreateWpCount(createWpCount);
            //归档数量
            int endCount = list.stream()
                    .map(SeatWorkReport::getEndCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setEndCount(endCount);
            //转督导
            int ddCount = list.stream()
                    .map(SeatWorkReport::getDdCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setDdCount(ddCount);
            //转质检
            int zjCount = list.stream()
                    .map(SeatWorkReport::getZjCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setZjCount(zjCount);

            //转培训助理
            int trainCount = list.stream()
                    .map(SeatWorkReport::getTrainCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setTrainCount(trainCount);

            //自办件
            int selfCount = list.stream()
                    .map(SeatWorkReport::getSelfCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setSelfCount(selfCount);

            //流转件
            int moveCount = list.stream()
                    .map(SeatWorkReport::getMoveCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setMoveCount(moveCount);

            int visitSucessCount = list.stream()
                    .map(SeatWorkReport::getVisitSucessCount)
                    .reduce(Integer::sum)
                    .orElse(0);
            report.setVisitSucessCount(visitSucessCount);

            list.add(report);

        }
        ExcelUtil<SeatWorkReport> util = new ExcelUtil<SeatWorkReport>(SeatWorkReport.class);
        util.exportExcel(response, list, "坐席工作情况表数据");
    }


}
